<template>
  <div class="play">
    <div class="titHead">
      <h3>推荐歌单</h3>
      <span class="more">
        <p>更多</p>
        <Svgview ion="#icon-youjiantou" />
      </span>
    </div>
    <div class="playList">
      <van-swipe :loop="false" :width="125" :show-indicators="false">
        <van-swipe-item v-for="item in paly" :key="item.id" @click="goPlayDetail(item.id)">
          <div class="playItem">
            <img :src="item.picUrl" alt="" />
            <span class="playCount">
              <Svgview ion="#icon-gl-play-copy" />
              {{ changeCount(item.playCount) }}
            </span>
            <div>{{ item.name }}</div>
          </div>
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { getPlayList } from "@/assets/axios/api";
import Svgview from "@/components/SvgView";
const paly = ref({});
const router = useRouter();
onMounted(async () => {
  let res = await getPlayList(6);
  paly.value = res.data.result;
});
const changeCount = (num) => {
  if (num > 100000000) {
    return (num / 100000000).toFixed(1) + "亿";
  } else if (num > 10000) {
    return (num / 10000).toFixed(1) + "万";
  } else {
    return num;
  }
};
const goPlayDetail = (id) => {
  router.push(`/playitem?id=${id}`);
};
</script>

<style scoped lang="less">
.play {
  background-color: white;

  .titHead {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    margin-bottom: 10px;

    .more {
      font-size: 0.24rem;
      border-radius: 15px;
      border: 1px silver solid;
      padding: 0 8px;
      height: 20px;
      line-height: 20px;
      margin-right: 10px;
      display: flex;
      flex-direction: row;
      align-items: center;

      .icon {
        width: 10px;
        height: 10px;
        margin-right: 0;
      }
    }
  }

  .playList {
    height: 160px;
    width: 100%;

    .playItem {
      text-align: center;
      position: relative;

      img {
        border-radius: 10px;
        width: 110px;
        height: 110px;
      }

      span {
        position: absolute;
        top: 5px;
        right: 10px;
        font-size: 10px;
        color: white;

        .icon {
          width: 10px;
          height: 10px;
          color: white;
        }
      }

      div {
        width: 100px;
        color: black;
        margin: 0 auto;
        font-size: 12px;
        display: -webkit-box;
        overflow: hidden;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }
    }
  }
}
</style>
